package com.gwt.boot.tools;

import java.time.Duration;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;

public class DateTimeTools {
    //系统默认时区
    private static final ZoneId ZONE_ID = ZoneId.systemDefault();

    /**
     * 计算日期相差分钟数据
     * @param start 开始时间
     * @param end   结束时间
     * @return Long
     */
    public static Long compareMinutes(LocalDateTime start, LocalDateTime end){
        // 转换为ZonedDateTime以考虑时区
        ZonedDateTime zonedStart = start.atZone(ZONE_ID);
        ZonedDateTime zonedEnd = end.atZone(ZONE_ID);
        // 计算Duration
        Duration duration = Duration.between(zonedStart, zonedEnd);
        // 将Duration转换为分钟
        return duration.toMinutes();
    }
}
